﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Proggy.Web.Cms.PropertyTypes;
using Proggy.Web.Cms.Repositories;
using Proggy.Data;

namespace Proggy.Web.Cms.ContentModel
{
    /// <summary>
    /// Represents a view model found in this application
    /// </summary>
    public class AvailableContentModel
    {
        /// <summary>
        /// The full assembly name
        /// </summary>
        public string AssemblyName { get; set; }

        /// <summary>
        /// The namespace
        /// </summary>
        public string Namespace { get; set; }

        /// <summary>
        /// The alias (eg ProggyNewsArticleViewModel = "ProggyNewsArticle")
        /// </summary>
        public string TypeAlias { get; set; }

        ///// <summary>
        ///// The namespace for the corresponding controller
        ///// </summary>
        public string ControllerNamespace { get; set; }

        /// <summary>
        /// The System.Type
        /// </summary>
        public Type Type { get; set; }

        /// <summary>
        /// The attribute for this view model
        /// </summary>
        public ContentModelAttribute ContentModelAttribute { get; set; }

        /// <summary>
        /// The friendly name for this view model type
        /// </summary>
        public string FriendlyName { get; set; }

        /// <summary>
        /// The tabs for this view model type
        /// </summary>
        public IEnumerable<AvailableTab> Tabs { get; set; }

        /// <summary>
        /// Allowed child types
        /// </summary>
        public List<string> AllowedChildTypeAliases { get; set; }

        /// <summary>
        /// Allowed template aliases
        /// </summary>
        public List<string> AllowedTemplates { get; set; }

        /// <summary>
        /// If true, will appear in list when creating root node
        /// </summary>
        public bool CanBeUsedForRootNode { get; set; }

        /// <summary>
        /// Returns controller type 
        /// </summary>
        /// <returns></returns>
        public Type GetControllerType()
        {
            return Type.GetType(this.ControllerNamespace + "." + this.TypeAlias + "Controller," + this.AssemblyName);
        }

        /// <summary>
        /// All available content models
        /// </summary>
        public Type AllAvailableContentModels { get; set; }
    }
}
